using MediatR;
using MeetingManagement.Domain.Entities;
using MeetingManagement.Domain.Repositories;

namespace MeetingManagement.Application.Commands.MeetingRooms.DeleteMeetingRoom
{
    public class DeleteMeetingRoomCommandHandler : IRequestHandler<DeleteMeetingRoomCommand, bool>
    {
        private readonly IRepository<MeetingRoom> _repository;

        public DeleteMeetingRoomCommandHandler(IRepository<MeetingRoom> repository)
        {
            _repository = repository;
        }

        public Task<bool> Handle(DeleteMeetingRoomCommand request, CancellationToken cancellationToken)
        {
            var room = _repository.Get(request.Id);
            if (room == null) return Task.FromResult(false);

            _repository.DeleteAsync(room);
            return Task.FromResult(true);
        }
    }
}
